package com.itboye.textileexpres.myset;

import java.util.ArrayList;
import java.util.List;

import android.R.integer;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.alipay.a.a.a;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.BaseActivity;

public class ActivityCustomerService extends BaseActivity implements
		OnClickListener {
	TextView title;
	ImageView back, img_other;
	TextView news, customer;
	View news_view, customer_view;
	ViewPager viewpager;
	List<Fragment> fragments;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_customerservice;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		title.setText(R.string.Customer_service);
		img_other.setVisibility(View.GONE);
		initTextview();
		initViewPager();
	}

	private void initViewPager() {
		// TODO Auto-generated method stub
		fragments = new ArrayList<Fragment>();
		FragmentNews fragmentNews = new FragmentNews();
		FragmentCustomer fragmentCustomer = new FragmentCustomer();
		fragments.add(fragmentNews);
		fragments.add(fragmentCustomer);
		viewpager.setAdapter(new MyPagerAdaper(getSupportFragmentManager(),
				fragments));
		viewpager.setCurrentItem(0);
		setTextColor(0);
		viewpager.setOnPageChangeListener(new MychangePager());
	}

	private void setTextColor(int i) {
		// TODO Auto-generated method stub
		switch (i) {
		case 0:
			news.setTextColor(getResources().getColor(R.color.green));
			news_view.setVisibility(View.VISIBLE);
			customer.setTextColor(getResources().getColor(R.color.black));
			customer_view.setVisibility(View.GONE);
			break;
		case 1:
			news.setTextColor(getResources().getColor(R.color.black));
			news_view.setVisibility(View.GONE);
			customer.setTextColor(getResources().getColor(R.color.green));
			customer_view.setVisibility(View.VISIBLE);
			break;
		default:
			break;
		}
	}

	private void initTextview() {
		// TODO Auto-generated method stub
		news.setOnClickListener(new textClick(0));
		customer.setOnClickListener(new textClick(1));
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;

		default:
			break;
		}
	}

	class textClick implements OnClickListener {
		int index = 0;

		public textClick(int i) {
			// TODO Auto-generated constructor stub
			index = i;
		}

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			viewpager.setCurrentItem(index);
		}

	}

	class MyPagerAdaper extends FragmentStatePagerAdapter {
		List<Fragment> list;

		public MyPagerAdaper(FragmentManager fm) {
			super(fm);
			// TODO Auto-generated constructor stub
		}

		public MyPagerAdaper(FragmentManager fm, List<Fragment> list) {
			// TODO Auto-generated constructor stub
			super(fm);
			this.list = list;
		}

		@Override
		public Fragment getItem(int arg0) {
			// TODO Auto-generated method stub
			return list.get(arg0);
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

	}

	class MychangePager implements OnPageChangeListener {

		@Override
		public void onPageScrollStateChanged(int arg0) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onPageSelected(int arg0) {
			// TODO Auto-generated method stub
			viewpager.setCurrentItem(arg0);
			setTextColor(arg0);
		}
	}
}
